<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Bacheca</title>
</head>
<body>
    <form name="bacheca" method="post" action="BachecaServlet">
      <input type="hidden" name="username" value="<%=request.getAttribute("username") %>">
      <input type="hidden" name="nome" value="<%=request.getAttribute("nome") %>">
      <input type="hidden" name="cognome" value="<%=request.getAttribute("cognome") %>">
   </form>
   <form name="notifiche" method="post" action="NotificheServlet">
      <input type="hidden" name="username" value="<%=request.getAttribute("username") %>">
      <input type="hidden" name="nome" value="<%=request.getAttribute("nome") %>">
      <input type="hidden" name="cognome" value="<%=request.getAttribute("cognome") %>">
   </form>
    <form name="ricerca" method="post" action="Ricerca.jsp">
      <input type="hidden" name="id" value="<%=request.getAttribute("username") %>">
      <input type="hidden" name="nome" value="<%=request.getAttribute("nome") %>">
      <input type="hidden" name="cognome" value="<%=request.getAttribute("cognome") %>">
   </form>
   <p>
      <a href="javascript:document.bacheca.submit()">Bacheca</a>
      <a href="javascript:document.notifiche.submit()">Notifiche</a>
      <a href="MostraMioProfiloServlet?id=<%= request.getAttribute("username") %>"><%= request.getAttribute("nome") %><%= request.getAttribute("cognome") %></a>
      <a href="javascript:document.ricerca.submit()">Ricerca</a>
      <a href="LogoutServlet?username=<%= request.getAttribute("username")%>&user=utente">Logout</a>
   </p>
   <form name="nuovoMessaggio" method="post" action="NuovoMsgDaBacheca.jsp">
      <input type="hidden" name="username" value="<%=request.getAttribute("username") %>">
      <input type="hidden" name="nome" value="<%=request.getAttribute("nome") %>">
      <input type="hidden" name="cognome" value="<%=request.getAttribute("cognome") %>">
   </form>
   <p><a href="javascript:document.nuovoMessaggio.submit()">Nuovo messaggio</a></p>
   
<% 
   int size = Integer.parseInt(request.getAttribute("size").toString());

   if(size == 0) {
	   
	   out.println(request.getAttribute("err"));
	   
   }
   else {
	   
	   out.println("<ul>");
       for(int i = 0; i < size; i++) {
     	  
     	  int dim = Integer.parseInt(request.getAttribute("dim" + i).toString());
     	  int id = Integer.parseInt(request.getAttribute("id" + i).toString());
     	  
     	  out.println("<li>"); 
     	  if(request.getAttribute("mittente" + i).toString().equals("Utente disiscritto")) {
     		  
     		 out.println("Mittente: " + request.getAttribute("mittente" + i) + "<br/>");
     		  
     	  }
     	  else {
     		  
     		  if(request.getAttribute("mittente" + i).toString().equals(request.getAttribute("username").toString())) {
     			  
     			 out.println("<a href=\"MostraMioProfiloServlet?id=" + request.getAttribute("username") + "\">");
     			  
     		  }
     		  else {
     			  
     			 out.println("<a href=\"ProfiloUtenteServlet?username=" + request.getAttribute("mittente" + i) + "&from=msg&id=" + request.getAttribute("username") + "\">");
     			  
     		  }
     		  
        	  out.println("Mittente: " + request.getAttribute("mittente" + i) + "<br/>");
        	  out.println("</a>");
     		  
     	  }
     	  
     	  out.println("Testo: " + request.getAttribute("testo" + i));
     	  
     	  if(dim != 0) {
     		  
     		  out.println("<ol>");
     		  for(int j = 0; j < dim; j++) {
     			  
     			  String mit = "mit" + Integer.toString(j) + Integer.toString(i);
				  String txt = "txt" + Integer.toString(j) + Integer.toString(i);
     			  
         		  out.println("<li>");
         		  if(request.getAttribute(mit).toString().equals("Utente disiscritto")) {
         			  
         			 out.println("Mittente: " + request.getAttribute(mit) + "<br/>");
         			  
         		  }
         		  else {
         			  
         			 if(request.getAttribute("username").toString().equals(request.getAttribute(mit).toString())) {
            			  
                    	  out.println("<a href=\"MostraMioProfiloServlet?id=" + request.getAttribute("username") + "\">");
            			  
            		  }
            		  else {
            			  
            			  out.println("<a href=\"ProfiloUtenteServlet?username=" + request.getAttribute(mit) + "&from=msg&id=" + request.getAttribute("username") + "\">");
            			  
            		  }
            		  out.println("Mittente: " + request.getAttribute(mit) + "<br/>");
            		  out.println("</a>");
         			  
         		  }
                  
         		  out.println("Commento: " + request.getAttribute(txt) + "</li>");
     			  
     		  } 
     		  
     		  out.println("</ol>");
     		  
     	  }
     	  
     	  out.println("<br/><a href=\"CommentaDaBacheca.jsp?idMsg=" + id + "&progressivo=" + dim + "&username=" + request.getAttribute("username") + "&nome=" + request.getAttribute("nome") + "&cognome=" + request.getAttribute("cognome") + "\"> Commenta");
 		  out.println("</a>");
     	  out.println("</li>");
     	  
       }
       
       out.println("</ul>");
	   
   }
%>   
</body>
</html>